﻿using System;
using System.Collections;

namespace HossMvp.Core
{
    public class ActionContext
    {
        public IPresenter<AbstractModelManager, AbstractViewManager> Presenter { get; internal set; }

        public IContentProvider Sender { get; internal set; }

        public IContentProvider Receiver { get; internal set; }

        public Hashtable Arguments { get; private set; }

        public ActionContext()
        {
            this.Arguments = new Hashtable();
        }

        public T Get<T>(string name)
        {
            var value = this.Arguments[name];
            T result;
            try
            {
                result = (T)value;
            }
            catch
            {
                try
                {
                    result = (T)Convert.ChangeType(value, typeof(T));
                }
                catch 
                {
                    result = default(T);
                }
            }

            return result;
        }
    }
}